<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>

    <input type="text" id="textInput"  />
    <input type="button" value="Start" onclick="javascript:start()" />
</div>
<div id="messages"></div>
<script type="text/javascript">
    var webSocket = new WebSocket('ws://localhost:88/ws');
    webSocket.onerror = function(event) {
        alert(event.data);
    };
    //与WebSocket建立连接
    webSocket.onopen = function(event) {
        document.getElementById('messages').innerHTML = '与服务器端建立连接';
    };
    //处理服务器返回的信息
    webSocket.onmessage = function(event) {
        document.getElementById('messages').innerHTML += '<br />'+ event.data;
    };
    function start() {
        //向服务器发送请求
        var t = document.getElementById("textInput").value;
        webSocket.send(t);
    }
</script>
</body>
</html>


